package main

import "fmt"

func swap(arr [3]int, i int, j int) {
	arr[i], arr[j] = arr[j], arr[i]
}

func swap2(arr *[3]int, i int, j int) {
	// (*arr)[i], (*arr)[j] = (*arr)[j], (*arr)[i]
	arr[i], arr[j] = arr[j], arr[i]

	fmt.Println("arr addr is ", &arr)
	fmt.Println("arr[1] addr is ", &arr[1])
	fmt.Println("arr[2] addr is ", &arr[2])
	fmt.Println("arr[2] val is ", arr[2])
}
func main() {
	var arr [3]int
	for i := 0; i < len(arr); i++ {
		arr[i] = i + 1
	}
	// for index, val := range arr {
	// 	fmt.Println(index, val)
	// }

	swap(arr, 0, 1)
	fmt.Println(arr[0]) // 1
	fmt.Println(arr[1]) // 2

	swap2(&arr, 0, 1)
	fmt.Println(arr[0]) // 2
	fmt.Println(arr[1]) // 1

	// tips
	// 数组是值传递
}
